﻿function EditUserGroupSubmit() {
    
}
function reloadUserPartial()
{
    var data = {};
    data["groupId"] = $("#groupList").val();
    data["searchString"] = $("#searchString").val();
    data["OrderNum"] = $("#OrderNum").val();
    //startAjaxWait();
    console.log(data);
    doAjaxHtml("Admin", "AllUsersPartial", data, null, "#userPartial");
}
function UserDelGroup(id,grName) {
    //alert(id +" " + grName);
    var userId = $("#Id").val();
    var data = {};
    data["userId"] = userId;
    data["groupId"] = id;
    console.log(data);
    doAjax("Admin", "EditUserEditGroup_DelGroup", data, function (data) { successDelGroupUser(id, grName); }, function (data) { errorFunc("error del!"); });
}
function UserAddGroup() {
    var grId = $("#NewGroupsList").val();
    if (grId == -1) return false;
    var uId = $("#Id").val();
    var data = {};
    data["userId"] = uId;
    data["groupId"] = grId;
    console.log(data);
    doAjax("Admin", "EditUserEditGroup_AddGroup", data, function (data) { successAddGroupUser(); }, function (data) { errorFunc("error add!"); });
}

function successDelGroupUser(id, grName) {
    //alert(grName);
    $('p#' + id).remove();
    if ($("select[id=NewGroupsList] option").size() == 1) $('#AddNewGroup').show();
    $('#NewGroupsList').append("<option value='" + id + "'>" + grName + "</option>");
}
function successAddGroupUser() {
    //alert("вернулся!");
    $('#UserGroups').append("<p id="+$("#NewGroupsList").val()+"><span class='lead'>"+$("#NewGroupsList :selected").html()+"</span>" +
       "<i class='icon-remove-sign' onclick='UserDelGroup(" + $("#NewGroupsList").val() + ",\"" + $("#NewGroupsList :selected").html() + "\");'></i></p>");
    
    $("#NewGroupsList :selected").remove();
    if ($("select[id=NewGroupsList] option").size() == 1) $('#AddNewGroup').hide();
}
function errorFunc(err) {
    alert(err);
}
function validatePass()
{
    var pass1 = $("#pass1").val();
    var pass2 = $("#pass2").val();
    if (pass1 != pass2)
    {
        console.log("fail");
        $("#pass1").css("border-color", "#ff0000");
    }
}
function delUser_fromAllUsersPage(e,id) {
    
    doAjaxDisableUser("Admin", "DeleteUser", { id: id });
    //$('#userId_' + id).remove();
    e.closest("tr").remove();
}